//
//  SellerOrderLsitViewController.m
//  SmartCoin
//
//  Created by apple on 2018/3/7.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "SellerOrderLsitViewController.h"
#import "SellerOrderListHeader.h"
#import "IncomeTableViewCell.h"//收入数字cell
#import "SellerFourBoxTableViewCell.h"//四宫格详情
#import "SellerDetailBussessTableViewCell.h"//交易详情
#import "DealInfoViewController.h"
static NSString *IncomeTableViewCellIndenfifier = @"IncomeTableViewCellIndenfifier";
static NSString *SellerFourBoxTableViewCellIndentifier = @"SellerFourBoxTableViewCellIndentifier";
static NSString *SellerDetailBussessTableViewCellIndentifier = @"SellerDetailBussessTableViewCellIndentifier";
@interface SellerOrderLsitViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,retain)UIScrollView *bgview;
@property (nonatomic ,retain)UITableView *leftView;
@property (nonatomic ,retain)UITableView *rightView;
@property (nonatomic ,retain)UIView *CoverView;
@property (nonatomic ,retain)UIButton *ringbtn;
@property (nonatomic ,retain)UIButton *currentseg;
@property (nonatomic ,assign)NSInteger currentSegNumber;
@property (nonatomic ,retain)UIView *coverbg;
@property (nonatomic ,retain)NSMutableDictionary *moneyData;
@property (nonatomic ,retain)NSMutableArray *buylist;
@property (nonatomic ,retain)NSMutableArray *integralLsit;
@property (nonatomic ,assign)NSInteger currentLeft;
@property (nonatomic ,assign)NSInteger currentRight;
@property (nonatomic ,retain)UIView *bgColorview;
@end

@implementation SellerOrderLsitViewController

-(instancetype)init{
    self = [super init];
    self.view.frame = CGRectMake(0, cxsingler.topdis, cx_wid, cx_hit - cxsingler.topdis - cxsingler.bottomdis - 50);
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(numberRefresh) name:@"numberrefresh" object:nil];
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self numberRefresh];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(numberRefresh) name:@"numberrefresh" object:nil];
    [super viewDidLoad];
    _moneyData = [@{
                    @"balanceArrived":@" 0",
                    @"bankArrived" : @"0",
                    @"orderCount" : @"0",
                    @"totalAmount" : @"0",
                    @"userCount" : @"0"} mutableCopy];
    _buylist = [NSMutableArray array];
    _integralLsit = [NSMutableArray array];
    _currentLeft = 1;
    _currentRight = 1;
    _currentSegNumber = 0;
    self.view.backgroundColor = bggrayColor;
//     [self bgLoad];buylist add
    
    
    [self viewLoad];
    [self coverViewload];
    [self dataLoad];
    [self bgLoad];
}

-(void)bgLoad{
    _bgColorview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2 * cx_wid, 235 / 2)];
    _bgColorview = [[UIView alloc] init];
    _bgColorview.backgroundColor = [CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1];
//    [self.view addSubview:_bgColorview];
//    [self.view sendSubviewToBack:_bgColorview];
//    [_bgColorview mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(0);
//        make.right.mas_equalTo(0);
//        make.top.mas_equalTo(0);
//        make.bottom.mas_equalTo(_leftView.mas_top);
//    }];
}

#pragma mark--数据请求
-(void)dataLoad{
    [self moneyDataLoad];
    [self buylistLoadWithmore:YES];
}

#pragma mark--资金数据获取
-(void)moneyDataLoad{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel getStoreDetailMoney];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        if ([result isEqual:@"success"]) {
            weakSelf.moneyData = [cxsingler.DicData mutableCopy];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (weakSelf.leftView) {
                [weakSelf.leftView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                }
                if (weakSelf.rightView) {
                    [weakSelf.leftView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
                }
            });
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}

#pragma mark--消费列表获取
-(void)buylistLoadWithmore:(BOOL)more{
    
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    if (!more) {
        _currentLeft = 1;
    }
    NSInteger currentpage = _currentLeft;
    [netmodel getStoreDetailBuessesswithpage:currentpage withOnlyToday:YES];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        [weakSelf.leftView.mj_footer endRefreshing];
        [weakSelf.leftView.mj_header endRefreshing];
        if ([result isEqual:@"success"]) {
            NSArray *list = cxsingler.ArraryData;
            if (cxsingler.ArraryData.count > 0) {
               
                if (!more) {
//                    [weakSelf.buylist removeAllObjects];
                    weakSelf.buylist = [NSMutableArray array];
                    weakSelf.currentLeft = 2;
                }
                else{
                     weakSelf.currentLeft ++;
                }
                for (NSDictionary *dic in list) {
                    [weakSelf.buylist addObject:dic];
                }
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [weakSelf.leftView reloadData];
                    });
            }
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}

-(void)integralDataLoad:(BOOL)more{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    if (!more) {
        _currentRight = 1;
    }
    NSInteger currentpage = _currentRight;
    [netmodel getDetailintegralwithpage:currentpage];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        [weakSelf.rightView.mj_footer endRefreshing];
        [weakSelf.rightView.mj_header endRefreshing];
        if ([result isEqual:@"success"]) {
            NSArray *list = cxsingler.ArraryData;
            if (cxsingler.ArraryData.count > 0) {
                if (more) {
                weakSelf.currentRight ++;
                }
                else{
                    weakSelf.currentRight = 2;
                }
                if (!more) {
                    [weakSelf.integralLsit removeAllObjects];
                }
                for (NSDictionary *dic in list) {
                    [weakSelf.integralLsit addObject:dic];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakSelf.rightView reloadData];
                });
            }
        }
        else{
//            [SVProgressHUD showErrorWithStatus:result];
        }
    };
}


-(void)coverViewload{
    if (!_CoverView) {
        _CoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, 255)];
//        _CoverView.backgroundColor = [UIColor purpleColor];
//        _CoverView.hidden = YES;
        [self.view addSubview:_CoverView];
        
//        UIView *topview = [[UIView alloc] initWithFrame:CGRectMake(0, cxsingler.topdis, cx_wid, 255)];
//        topview.backgroundColor = [UIColor purpleColor];
//        self.view.backgroundColor = [UIColor orangeColor];
//        [self.view addSubview:topview];
        
        UIButton *popbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
        [popbtn setImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
        [popbtn addTarget:self action:@selector(popbtnClick:) forControlEvents:UIControlEventTouchUpInside];
        //        _coverbg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, 235)];
        _coverbg = [[UIView alloc]init];
        _coverbg.layer.shadowOffset = CGSizeMake(3, 3);
        _coverbg.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        [_CoverView addSubview:_coverbg];
        [_coverbg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(-20);
            make.top.mas_equalTo(0);
        }];
        
        _ringbtn = [[UIButton alloc] initWithFrame:CGRectMake(cx_wid - 44, 0, 44, 44)];
        [_ringbtn addTarget:self action:@selector(ringbtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_ringbtn setImage:[UIImage imageNamed:@"header_notice"] forState:UIControlStateSelected];
        [_ringbtn setImage:[UIImage imageNamed:@"header_silence"] forState:UIControlStateNormal];
        if ([cxsingler.loginrequest[@"voiceState"] boolValue] == 1) {
            _ringbtn.selected = YES;
            cxsingler.shouldRing = YES;
        }
        else{
            _ringbtn.selected = NO;
            cxsingler.shouldRing = NO;
        }
        
        [_CoverView addSubview:popbtn];
        popbtn.hidden = YES;
        [_CoverView addSubview:_ringbtn];
        
        UIView *segview = [[UIView alloc] init];
        segview.backgroundColor = [UIColor whiteColor];
        segview.layer.shadowOffset = CGSizeMake(3, 3);
        segview.layer.shadowOpacity = 0.4;
        segview.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        [_CoverView addSubview:segview];
        [segview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(0);
            make.left.mas_equalTo(44);
            make.right.mas_equalTo(-44);
            make.height.mas_equalTo(40);
        }];
        segview.layer.cornerRadius = 20;
        segview.layer.shadowOffset = CGSizeMake(3, 3);
        UIView *centverline = [[UIView alloc] initWithFrame:CGRectMake(cx_wid / 2 - 44 - 0.25, 0, 0.5, 40)];
        centverline.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
        [segview addSubview:centverline];
        
        NSArray *segs = @[@"门店",@"积分池"];
        for (NSInteger index = 0; index < 2; index ++) {
            UIButton *segbtn = [[UIButton alloc] initWithFrame:CGRectMake((cx_wid / 2 - 44) * index, 0, cx_wid / 2 - 44, 40)];
            [segbtn setTitle:segs[index] forState:UIControlStateNormal];
            [segbtn setTitleColor:[CXSinglerModel colorWithHex:@"fb4a41" alpha:1] forState:UIControlStateSelected];
            [segbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            if (index == 0) {
                segbtn.selected = YES;
                _currentseg = segbtn;
            }
            [segbtn addTarget:segs action:@selector(segbtn:) forControlEvents:UIControlEventTouchUpInside];
            [segview addSubview:segbtn];
        }
        
    }
}



-(void)viewLoad{
    if (!_bgview) {
        _bgview = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        if (@available(iOS 11.0, *)) {
            _bgview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        _bgview.contentSize = CGSizeMake(cx_wid * 2, cx_hit - cxsingler.topdis - cxsingler.bottomdis - 50);
        _bgview.scrollEnabled = NO;
        _bgview.pagingEnabled = YES;
        [self.view addSubview:_bgview];
//        [self.view sendSubviewToBack:_bgview];
        [self loadleft];
        [self loadright];
    }
}

#pragma mark--门店部分
-(void)loadleft{
    if (!_leftView) {
        _leftView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, cx_hit - cxsingler.topdis - cxsingler.bottomdis - 50)];
        _leftView.backgroundColor  = [UIColor clearColor];
        _leftView.estimatedRowHeight = 0;
        WEAKSELF;
        MJRefreshGifHeader *Gifheader = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            [weakSelf buylistLoadWithmore:NO];
        }];
        MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
            [weakSelf buylistLoadWithmore:YES];
        }];
        [Gifheader setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
        [Gifheader setTitle:@"松开刷新" forState:MJRefreshStatePulling];
        [Gifheader setTitle:@"刷新中……" forState:MJRefreshStateRefreshing];
        [footer setTitle:@"上拉加载更多" forState:MJRefreshStateIdle];
        [footer setTitle:@"松开加载更多" forState:MJRefreshStatePulling];
        [footer setTitle:@"加载更多中……" forState:MJRefreshStateRefreshing];
        _leftView.mj_header = Gifheader;
        _leftView.mj_footer = footer;
        if (@available(iOS 11.0, *)) {
            _leftView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        _leftView.delegate = self;
        _leftView.dataSource = self;
        [_leftView registerClass:[IncomeTableViewCell class] forCellReuseIdentifier:IncomeTableViewCellIndenfifier];
        [_leftView registerClass:[SellerFourBoxTableViewCell class] forCellReuseIdentifier:SellerFourBoxTableViewCellIndentifier];
        [_leftView registerClass:[SellerDetailBussessTableViewCell class] forCellReuseIdentifier:SellerDetailBussessTableViewCellIndentifier];
        _leftView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_bgview addSubview:_leftView];
        [_bgview sendSubviewToBack:_leftView];
    }
}

#pragma mark--积分池部分
-(void)loadright{
    if (!_rightView) {
        _rightView = [[UITableView alloc] initWithFrame:CGRectMake(cx_wid, 0, cx_wid, cx_hit - cxsingler.topdis - cxsingler.bottomdis - 50)];
        _rightView.estimatedRowHeight = 0;
        _rightView.backgroundColor = [UIColor clearColor];
        WEAKSELF;
        MJRefreshGifHeader *Gifheader = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            [weakSelf integralDataLoad:NO];
        }];
        MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
            [weakSelf integralDataLoad:YES];
        }];
        [Gifheader setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
        [Gifheader setTitle:@"松开刷新" forState:MJRefreshStatePulling];
        [Gifheader setTitle:@"刷新中……" forState:MJRefreshStateRefreshing];
        [footer setTitle:@"上拉加载更多" forState:MJRefreshStateIdle];
        [footer setTitle:@"松开加载更多" forState:MJRefreshStatePulling];
        [footer setTitle:@"加载更多中……" forState:MJRefreshStateRefreshing];
        _rightView.mj_header = Gifheader;
        _rightView.mj_footer = footer;
        if (@available(iOS 11.0, *)) {
            _rightView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        _rightView.delegate = self;
        _rightView.dataSource = self;
        [_rightView registerClass:[IncomeTableViewCell class] forCellReuseIdentifier:IncomeTableViewCellIndenfifier];
        [_rightView registerClass:[SellerDetailBussessTableViewCell class] forCellReuseIdentifier:SellerDetailBussessTableViewCellIndentifier];
        _rightView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_bgview addSubview:_rightView];
        [_bgview sendSubviewToBack:_rightView];
    }
    [self integralDataLoad:YES];
}



#pragma mark--tableview代理
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([tableView isEqual:_rightView]) {
        if (section == 0) {
            return 1;
        }
        else{
            return _integralLsit.count;
        }
    }
    if (section == 0) {
        return 2;
    }
    else{
        return _buylist.count;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    NSInteger sec = indexPath.section;
    if ([tableView isEqual:_rightView]) {
        if (sec == 0) {
            return 235;
        }
        else{
            return 53;
        }
    }
    if (sec == 0) {
        if (row == 0) {
            return 235;
        }
        else if(row == 1){
            return 170;
        }
    }
    else if (sec == 1){
        return 53;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 64;
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        SellerOrderListHeader *headerview = [[SellerOrderListHeader alloc] initWithFrame:CGRectMake(0, 0, cx_wid, 64)];
        headerview.dateLabel.text = @"今日";
        return headerview;
    }
    else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
        return view;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    NSInteger sec  = indexPath.section;
    if ([tableView isEqual:_leftView]) {
        if (sec == 0 && row == 0) {//收入显示
            IncomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IncomeTableViewCellIndenfifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.bgview.backgroundColor = [CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1];
            //        cell.bgview.backgroundColor = [UIColor orangeColor];
            cell.deslabel.text = @"今日收入";
            cell.moneylabel.text = [NSString stringWithFormat:@"%.2lf",[_moneyData[@"totalAmount"] floatValue] / 100];
            return cell;
        }
        if (sec == 0 && row == 1) {//收入明细四格展示
            SellerFourBoxTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SellerFourBoxTableViewCellIndentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.money.text = [NSString stringWithFormat:@"%.2lf",[_moneyData[@"bankArrived"] floatValue] / 100];
            cell.points.text = [NSString stringWithFormat:@"%ld",[_moneyData[@"balanceArrived"] integerValue]];
            cell.deals.text = [NSString stringWithFormat:@"%ld",[_moneyData[@"orderCount"] integerValue]];
            cell.buyers.text = [NSString stringWithFormat:@"%ld",[_moneyData[@"userCount"] integerValue]];
            cell.backgroundColor = bggrayColor;
            return cell;
        }
        else{
            SellerDetailBussessTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SellerDetailBussessTableViewCellIndentifier];
            NSDictionary *part = _buylist[row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.header sd_setBackgroundImageWithURL:[NSURL URLWithString:part[@"avatar"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"logo1"]];
            cell.namelabel.text = part[@"userName"];
            cell.timelabel.text = [self gettimeByInter:[[[NSString stringWithFormat:@"%@",part[@"createTime"]] substringWithRange:NSMakeRange(0, 10)] integerValue]];
            cell.riselabel.text = [NSString stringWithFormat:@"+%.2lf",[part[@"price"] floatValue] / 100];
            return cell;
        }
    }
    else{//rightviewcell
        if (sec == 0 && row == 0) {//收入显示
            IncomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IncomeTableViewCellIndenfifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.bgview.backgroundColor = [CXSinglerModel colorWithHex:@"#F58A40" alpha:1];
            //        cell.bgview.backgroundColor = [UIColor orangeColor];
            cell.deslabel.text = @"今日收入";
            cell.moneylabel.text = [NSString stringWithFormat:@"%.2lf",[_moneyData[@"totalAmount"] floatValue]];
            return cell;
        }
        else{
            SellerDetailBussessTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SellerDetailBussessTableViewCellIndentifier];
            NSDictionary *part = _integralLsit[row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.header sd_setBackgroundImageWithURL:[NSURL URLWithString:part[@"avatar"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"logo1"]];
            cell.namelabel.text = part[@"nickname"];
            cell.timelabel.text = [self gettimeByInter:[[[NSString stringWithFormat:@"%@",part[@"create_time"]]  substringWithRange:NSMakeRange(0, 10)] integerValue]];
            cell.riselabel.text = [NSString stringWithFormat:@"+%ld",[part[@"integral"] integerValue]];
            return cell;
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    NSInteger sec = indexPath.section;
    if ([tableView isEqual:_leftView]) {
        if (sec == 1) {
            NSMutableDictionary *part = _buylist[row];
            DealInfoViewController *nextVC = [[DealInfoViewController alloc] init];
            [nextVC loadWithInfo:part];
            [self.parentViewController.navigationController pushViewController:nextVC animated:YES];
        }
    }
}

#pragma mark--点击
-(void)segbtn:(UIButton *)sender{
    [self.view endEditing:YES];
    if ([sender isEqual:_currentseg]) {
        
    }
    else{
        _currentseg.selected = NO;
        sender.selected = YES;
        _currentseg = sender;
        [self scrollpage];
    }
}

-(void)scrollpage{
    if (_bgview.contentOffset.x > 0) {
        _currentSegNumber = 0;
    }
    else{
        _currentSegNumber = 1;
    }
    [self autoplacewithSeg:_currentSegNumber + 10];
    [_bgview setContentOffset:CGPointMake(_currentSegNumber * cx_wid, 0) animated:YES];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if ([scrollView isEqual:_leftView]) {
        [self autoplacewithSeg:0];
    }
    else if ([scrollView isEqual:_rightView]){
        [self autoplacewithSeg:1];
    }
}

#pragma mark--悬浮自动位置
-(void)autoplacewithSeg:(NSInteger)seg{
    if (seg >= 10) {
        seg = seg % 10;
        CGFloat offsety;
        UIColor *rightcolor;
        NSString *colorcode;
        CGRect rect;
        if (seg == 0) {
            offsety = _leftView.contentOffset.y;
            colorcode = @"#FF7F5A";
            rect = CGRectMake(0, 0, cx_wid, 44  + 30);
        }
        else{
            offsety = _rightView.contentOffset.y;
            colorcode = @"#F58A40";
        }
        if (offsety>= 255 - (44 ) - 30) {
            rightcolor = [CXSinglerModel colorWithHex:colorcode alpha:1];
            rect = CGRectMake(0, 0, cx_wid, 44  + 30);
        }
        else{
            if (offsety < 0) {
                rightcolor = [CXSinglerModel colorWithHex:colorcode alpha:0];
                rect = CGRectMake(0, 0, cx_wid, 255 - _leftView.contentOffset.y);
            }
            else{
                rightcolor =  [CXSinglerModel colorWithHex:colorcode alpha: offsety / (255 - (44 ) - 30)];
                rect = CGRectMake(0, 0, cx_wid, 255 - offsety);
            }
        }
        WEAKSELF;
        [UIView animateWithDuration:0.1 animations:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                weakSelf.coverbg.backgroundColor = rightcolor;
//                weakSelf.bgColorview.backgroundColor = [CXSinglerModel colorWithHex:colorcode alpha: 1];
//                [weakSelf.bgColorview mas_updateConstraints:^(MASConstraintMaker *make) {
//                    make.left.mas_equalTo(0);
//                    make.right.mas_equalTo(0);
//                    make.top.mas_equalTo(0);
//                    if (seg == 0) {
//                    make.bottom.mas_equalTo(_leftView.mas_top);
//                    }
//                    else{
//                    make.bottom.mas_equalTo(_rightView.mas_top);
//                    }
//                }];
                _CoverView.frame = rect;
            });
        }];
        return;
    }
    CGRect rect;
    CGFloat offsety;
    if (seg == 0) {//leftview
        offsety = _leftView.contentOffset.y;
        if (offsety >= 0) {
            if (offsety >= 255 - (44 ) - 30) {
                NSLog(@"-1");
                rect = CGRectMake(0, 0, cx_wid, 44  + 30);
                _coverbg.backgroundColor = [CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1];
            }
            else{
                NSLog(@"-2");
                _coverbg.backgroundColor = [CXSinglerModel colorWithHex:@"#FF7F5A" alpha: offsety / (255 - (44 ) - 30)];
                rect = CGRectMake(0, 0, cx_wid, 255 - offsety);
            }
        }
        else{
            NSLog(@"-3");

            _coverbg.backgroundColor = [CXSinglerModel colorWithHex:@"#FF7F5A" alpha:0];
            rect = CGRectMake(0, 0, cx_wid, 255 - offsety);
        }
    }
    else{//rightView
        offsety = _rightView.contentOffset.y;
        if (offsety >= 0) {
            if (offsety >= 255 - (44 ) - 30) {
                NSLog(@"-1");
                rect = CGRectMake(0, 0, cx_wid, 44  + 30);
                _coverbg.backgroundColor = [CXSinglerModel colorWithHex:@"#F58A40" alpha:1];
            }
            else{
                NSLog(@"-2");
                _coverbg.backgroundColor = [CXSinglerModel colorWithHex:@"#F58A40" alpha: offsety / (255 - (44 ) - 30)];
                rect = CGRectMake(0, 0, cx_wid, 255 - offsety);
            }
        }
        else{
            NSLog(@"-3");
            _coverbg.backgroundColor = [CXSinglerModel colorWithHex:@"#F58A40" alpha:0];
            rect = CGRectMake(0, 0, cx_wid, 255 - offsety);
        }
    }
    [UIView animateWithDuration:0.1 animations:^{
        _CoverView.frame = rect;
    }];
}

-(void)popbtnClick:(UIButton *)sender{
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)ringbtnClick:(UIButton *)sender{
    NetWorkModel *netmodel = [[NetWorkModel alloc] init];
    [netmodel changeringstatus:!sender.selected];
    WEAKSELF;
    netmodel.sendMessage = ^(NSString *result) {
        if ([result isEqual:@"success"]) {
            weakSelf.ringbtn.selected = !weakSelf.ringbtn.selected;
            cxsingler.shouldRing = weakSelf.ringbtn.selected;
            [SVProgressHUD showSuccessWithStatus:@"闹铃状态修改成功"];
        }
        else{
            [SVProgressHUD showErrorWithStatus:result];
        }
    };
    [self.view endEditing:YES];
}

-(void)numberRefresh{
//    cxsingler.loginrequest[@"admin"][@"shop_id"]
    if ([[cxsingler.loginrequest objectForKey:@"admin"] objectForKey:@"shop_id"]) {
    [self moneyDataLoad];
    [self buylistLoadWithmore:NO];
    [self integralDataLoad:NO];
    }
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
